package com.bayleaf.web.camelCase;

import javax.servlet.annotation.WebInitParam;
import javax.servlet.annotation.WebServlet;

import com.bayleaf.common.StringUtil;
import com.bayleaf.core.BayleafServlet;
import com.bayleaf.core.Model;


@WebServlet(name="camelCase",
        urlPatterns={"/camelCase"},
        initParams={ @WebInitParam(name="title", value="CamelCase <--> Under Score notation"), @WebInitParam(name="jsp", value="/camelCase/CamelCase") } )
public class CamelCaseServlet extends BayleafServlet {
	
    @Override
    public String process(Model model) throws Exception{
    	
    	String input = model.getString("input");
    	String reverse_input = model.getString("reverse_input");
    	
    	if("".equals(reverse_input)){
//    		System.out.println(input);
//    		System.out.println(camelCaseToUnderScore(input));
    		model.setString("output", camelCaseToUnderScore(input));
    	}else{
    		model.setString("output", underScoreToCamelCase(reverse_input));
    	}
        
        return null;
    }
    
    /**
     * 카멜케이스 형식의 스트링을 언더바 구분으로 바꿈 
     * @param camelCaseStr
     * @return underScoreResult
     */
    public static String camelCaseToUnderScore(String camelCaseStr){
    	return StringUtil.camelCaseToUnderScore(camelCaseStr);
    }
    
    /**
     * 언더바 형식의 스트링을 카멜케이스로 바꿈
     * @param underScore
     * @return camelCaseResult
     */
    public static String underScoreToCamelCase(String underScore){
    	return StringUtil.underScoreToCamelCase(underScore);
    }
    
}
